<!--
 * @Description: 货位管理
 * 
 * @Author: Edan<Edan>
 * @Date: 2024-07-30 08:49:19
 * @FilePath: /yuxiuproweb/src/views/mes/wm/warehouseLocation/index.vue
-->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
    >
      <el-form-item label="货位编码" prop="areaCode">
        <el-input
          v-model="queryParams.areaCode"
          placeholder="请输入货位编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="货位名称" prop="areaName">
        <el-input
          v-model="queryParams.areaName"
          placeholder="请输入货位名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          @click="handleDelete"
          >删除</el-button
        >
      </el-col>

      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-table
      v-loading="loading"
      :data="addressList"
      @selection-change="handleSelectionChange"
      :max-height="maxHeight"
    >
      <el-table-column type="selection" width="55" align="center" />
      <template v-for="(i, index) in tableForm.item">
        <el-table-column
          :key="index"
          :prop="i.itemcode"
          :columnKey="i.itemcode"
          :label="i.itemname"
          :align="i.aligntype ? i.aligntype : 'center'"
          :min-width="i.minwidth"
          :show-overflow-tooltip="i.overflow ? true : false"
          :sortable="i.sortable ? true : false"
          v-if="i.displaymark ? true : false"
        >
          <template slot-scope="scope">
            <div v-if="i.itemcode == 'enableFlag'">
              <span v-if="scope.row[i.itemcode] == 1">是</span>
              <span v-else>否</span>
            </div>
            <span v-else>{{ scope.row[i.itemcode] }}</span>
          </template>
        </el-table-column>
      </template>
      <el-table-column
        label="操作"
        align="center"
        width="220px"
        class-name="small-padding fixed-width"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handlePrint(scope.row)"
            >打印标签</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            style="color: #ff9292"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改高端定制对话框 -->
    <add-view
      v-if="open.show"
      :show.sync="open.show"
      v-bind="open"
      @update="getList"
    ></add-view>
  </div>
</template>

<script>
import {
  getWarehouseLocationList,
  delWarehouseLocation,
} from "@/api/mes/wm/warehouseLocation";
import AddView from "./mods/add.vue";
import { tableList } from "./mods/tablecolums.js";
import commonMix from "@/utils/mixins/common";
import { getLodop, loadCLodop } from "@/utils/LodopFuncs";
export default {
  name: "shipAddress",
  components: {
    AddView,
  },
  mixins: [commonMix],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 表格数据
      addressList: [],
      // 是否显示弹出层
      open: {
        show: false,
        type: "add",
        data: null,
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        areaCcode: null,
        areaName: null,
      },
      //
      tableForm: tableList,
    };
  },
  created() {
    this.getList();
  },
  mounted() {
    loadCLodop();
  },
  methods: {
    /** 查询高端定制列表 */
    getList() {
      this.loading = true;
      var queryParams = {
        pageNum: this.queryParams.pageNum,
        pageSize: this.queryParams.pageSize,
        areaCode: this.queryParams.areaCode,
        areaName: this.queryParams.areaName,
      };
      getWarehouseLocationList(queryParams).then((res) => {
        this.addressList = res.rows;
        this.total = res.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.areaId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd(row) {
      const datarow = { ...row } || null;
      this.open = {
        show: true,
        type: "add",
        data: datarow,
      };
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.open = {
        show: true,
        type: "edit",
        data: {
          ...row,
        },
      };
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const projectIds = row.areaId || this.ids;
      this.$modal
        .confirm("该操作不可逆，是否确定删除？")
        .then(function () {
          return delWarehouseLocation(projectIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    handlePrint(row) {
      const LODOP = getLodop();
      if (!LODOP) return;
      LODOP.PRINT_INIT("标签打印");
      LODOP.SET_PRINT_PAGESIZE(1, "50mm", "60mm", "");
      LODOP.ADD_PRINT_BARCODE(
        "5mm",
        "2mm",
        "48mm",
        "48mm",
        "QRCode",
        row.areaName
      );
      LODOP.ADD_PRINT_TEXT("50mm", "1mm", "50mm", "5mm", row.areaName);
      LODOP.SET_PRINT_STYLEA(0, "FontSize", 14);
      LODOP.SET_PRINT_STYLEA(0, "FontColor", "#000000");
      LODOP.SET_PRINT_STYLEA(0, "FontName", "Arial");
      LODOP.SET_PRINT_STYLEA(0, "Bold", 1);
      LODOP.SET_PRINT_STYLEA(0, "Alignment", 2);
      LODOP.PREVIEW();
    },
  },
};
</script>
